﻿namespace dogd
{
	/// <summary>
	/// OrderBy is used in sql generation by SqlStatementGenerator.
	/// </summary>
	public class OrderBy
	{
		/// <summary>
		/// Initializes default instance.
		/// </summary>
		public OrderBy()
		{
		}

		/// <summary>
		/// Initialize based on a column name and a sort order.
		/// </summary>
		/// <param name="columnName"></param>
		/// <param name="order"></param>
		public OrderBy(string columnName, SortOrder order)
		{
			this.ColumnName = columnName;
			this.Order = order;
		}

		/// <summary>
		/// The name of the column in the database.
		/// </summary>
		public string ColumnName
		{
			get;
			set;
		}

		/// <summary>
		/// How to return the data - ascending or descending.
		/// </summary>
		public SortOrder Order
		{
			get;
			set;
		}

		/// <summary>
		/// Override to provide sql fragment for this object.
		/// </summary>
		/// <returns></returns>
		public override string ToString()
		{
			return string.Format(
				"ORDER BY {0} {1}", 
				this.ColumnName, 
				this.Order.ToDescription());
		}
	}
}
